<template>
  <main-container v-if="navList.length > 0" class="main-only-box-bg-gray" :navList.sync="navList" :options="options" :isShowIframeHeader="false" :is-tab="false" />
</template>

<script>
  import MainContainer from '@/common/components/mainContainerMenu';
  import { apiContractInfo } from '../../../api/contract';

  export default {
    name: 'InformMain',

    components: {
      MainContainer,
    },

    data() {
      return {
        contractStatus: '',
        options: [],
        navList: [],
        payInfoNavList: [
          {
            name: '合同信息',
            menuUrl: '/businessAssets/ContractManage/payinfo',
          },
        ],
        infoNavList: [
          {
            name: '合同信息',
            menuUrl: '/businessAssets/ContractManage/info',
          },
        ],
        addNavList: [
          {
            name: '合同信息',
            menuUrl: '/businessAssets/ContractManage/create',
          },
        ],
        approveNavList: [
          {
            name: '审批信息',
            menuUrl: '/businessAssets/ContractManage/approve',
          },
        ],
        billNavList: [
          {
            name: '合同账单',
            menuUrl: '/businessAssets/ContractManage/bill',
          },
        ],
        expendNavList: [
          {
            name: '支出明细',
            menuUrl: '/businessAssets/ContractManage/expendDetail',
          },
        ],
      };
    },
    mounted() {
      this.getContractInfo();
    },

    methods: {
      //合同详情
      async getContractInfo() {
        let res = {};
        if (this.$route.query.contractKey) {
          let res = await apiContractInfo({ primaryKey: this.$route.query.contractKey });
          this.contractStatus = res.contractStatus;
        }

        // 支出合同没有账单信息
        if (this.$route.query.contractCategory == 2) {
          this.billNavList = []
        }

        this.initNavList();
      },

      //初始化tab
      initNavList() {
        //合同草稿 审批
        if (this.$route.name == 'contract-create') {
          if (!this.contractStatus) {
            this.navList = [...this.addNavList];
          } else if (this.contractStatus == 1) {
            if (this.$route.query.showApprove == 'no') {
              this.navList = [...this.addNavList, ...this.billNavList];
            } else {
              this.navList = [...this.addNavList, ...this.billNavList, ...this.approveNavList];
            }
          } else {
            this.navList = [...this.addNavList];
          }
        }

        if (this.$route.name == 'contract-bill' || this.$route.name == 'contract-approve') {
          let list = !this.contractStatus || this.contractStatus == 1 ? this.addNavList : this.infoNavList;
          if (this.$route.query.showApprove == 'no') {
            this.navList = [...list, ...this.billNavList];
          } else {
            if (this.contractStatus == 1) {
              this.navList = [...list, ...this.billNavList, ...this.approveNavList];
            } else {
              this.navList = [...list, ...this.billNavList];
            }
          }
        }

        //合同详情
        if (this.$route.name == 'contract-info') {
          let contractCategory = this.$route.query.contractCategory;
          let list = contractCategory == 1 ? this.billNavList : this.expendNavList;
          if (this.$route.query.showApprove == 'no') {
            this.navList = [...this.infoNavList, ...list];
          } else {
            if (this.contractStatus == 1) {
              this.navList = [...this.infoNavList, ...list, ...this.approveNavList];
            } else {
              this.navList = [...this.infoNavList, ...list];
            }
          }
        }

        if (this.$route.name == 'contract-expend-detail') {
          this.navList = [...this.infoNavList, ...this.expendNavList];
        }

        if (this.$route.name == 'contract-manage-pay-info') {
          this.navList = this.payInfoNavList;
        }
      },
    },
  };
</script>
